<template>
  <cs-container :is-back-to-top="true">
    <page-header
      slot="header"
      :loading="loading"
      :group="group"
      @submit="handleSubmit"
      ref="header"/>

    <page-main
      :loading="loading"
      :table-data="table"
      :group="group"
      @sort="handleSort"
      @refresh="handleRefresh"/>

    <!-- <page-footer
      slot="footer"
      :loading="loading"
      :current="page.current"
      :size="page.size"
      :total="page.total"
      @change="handlePaginationChange"/> -->
  </cs-container>
</template>

<script>
import { getClientType } from '@/api/public'
// import { getActionLogList } from '@/api/auth/action'
// import { getParentDictTable } from '@/api/auth/dict'

export default {
  name: 'system-auth-action',
  components: {
    'PageHeader': () => import('./components/PageHeader'),
    'PageMain': () => import('./components/PageMain')
    // 'PageFooter': () => import('@/layout/header-aside/components/footer')
  },
  data() {
    return {
      loading: true,
      group: [],
      table: [],
      page: {
        current: 1,
        size: 0,
        total: 0
      },
      order: {
        order_type: undefined,
        order_field: undefined
      }
    }
  },
  mounted() {
    Promise.all([
      getClientType(),
      this.$store.dispatch('kando/db/databasePage', { user: true })
    ])
      .then(res => {
        this.group = res[0] || []
        this.page.size = res[1].get('size').value() || 50
      })
      .then(() => {
        this.handleSubmit()
      })
  },
  methods: {
    // 刷新列表页面
    handleRefresh(isTurning = false) {
      if (isTurning) {
        !(this.page.current - 1) || this.page.current--
      }

      this.$nextTick(() => {
        this.$refs.header.handleFormSubmit()
      })
    },
    // 分页变化改动
    // handlePaginationChange(val) {
    //   this.page = val
    //   this.$nextTick(() => {
    //     this.$refs.header.handleFormSubmit()
    //   })
    // },
    // 排序刷新
    handleSort(val) {
      this.order = val
      this.$nextTick(() => {
        this.$refs.header.handleFormSubmit()
      })
    },
    handleSubmit(form, isRestore = false) {
      if (isRestore) {
        this.page.current = 1
      }

      this.loading = true
      // getActionLogList({
      //   ...form,
      //   ...this.order,
      //   page_no: this.page.current,
      //   page_size: this.page.size
      // })
      //   .then(res => {
      //     this.table = res.data.items || []
      //     this.page.total = res.data.total_result
      //   })
      //   .finally(() => {
      //     this.loading = false
      //   })
    }
    // 提交表单
    // handleSubmit(from) {
    // }
  }
}
</script>
